<?php
namespace Admin_\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function __construct()
    {
        parent::__construct();
//        var_dump(__ROOT__.APP_PATH.'/Public');
//        var_dump(__ROOT__);die;
        $this->_login = A('Login');
        //判断是否登录
        if(!$this->_login->check_login()){
            $this->_login->to_login();die;
        }
    }

    public function index(){
        $this->display();
    }


    /**
     * 编辑配置
     */
    public function config(){
        if(IS_POST) {
            $configs = I('post.config');
            $status = false;
            D()->startTrans();
            foreach($configs as $k => $v){
                if(D('config')->where(array( 'name' => $k,
                ))->setField(array('value' => $v))){
                    $status = true;
                }
                else{
                    $status = false;
                    continue;
                }
            }
            if($status){
                D()->commit();
                JSON(array('code'=>100,'message'=>'操作成功','data'=>array('go_url'=>U('Index/config'))));
            }else{
                D()->rollback();
                D()->commit();
                JSON(array('code'=>101,'message'=>'操作失败'));
            }
        }
        $config_list = M('config')->where(array('status'=>1))->select();
//        var_dump($config_list);die;
        $this->assign('config_list',$config_list);
        $this->display();
    }
}